package com.WebProject.mapper;

import com.WebProject.dao.BaseDao;
import com.WebProject.pojo.t_car;
import com.WebProject.pojo.t_car_Interger;
import com.WebProject.pojo.t_car_zu;
import com.WebProject.pojo.t_user;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;

public class UserMapperImpl extends BaseDao implements UserMapper {

    private SqlSession sqlSession = getConntion();
    private UserMapper usersmapper = sqlSession.getMapper(UserMapper.class);

    /**
     * 租车是否成功
     * @param username
     * @return
     */
    @Override
    public Boolean updateZuCarStatus(String username,String car_number) {

        Boolean aBoolean = usersmapper.updateZuCarStatus(username, car_number);

        sqlSession.commit();

        return aBoolean;
    }



    /**
     * 还车
     * @param car_number 车牌
     * @return 还车是否成功
     */
    @Override
    public Boolean updateHuanCarStatus(String car_number) {

        Boolean aBoolean = usersmapper.updateHuanCarStatus(car_number);

        sqlSession.commit();

        return aBoolean;
    }

    /**
     * 注册用户
     * @param user t_user Bean
     * @return 是否成功注册
     */
    @Override
    public Boolean registerUser(t_user user) {

        Boolean aBoolean = usersmapper.registerUser(user);

        sqlSession.commit();


        return aBoolean;
    }

    /**
     * 查询所有汽车(t_car)表
     * @return 所有汽车集合
     */
    @Override
    public ArrayList<t_car> QueryAllCarInfo() {
        return usersmapper.QueryAllCarInfo();
    }

    @Override
    public ArrayList<t_user> QueryAllUserInfo() {
        return usersmapper.QueryAllUserInfo();
    }

    @Override
    public ArrayList<t_car> QueryAllTypeCar(String Type) {
        return usersmapper.QueryAllTypeCar(Type);
    }

    @Override
    public ArrayList<t_car> QueryAllBrandCar(String Brand) {
        return usersmapper.QueryAllBrandCar(Brand);
    }

    @Override
    public ArrayList<t_car_zu> QuerUserZuInfo(String username) {
        return usersmapper.QuerUserZuInfo(username);
    }

    @Override
    public t_car QueryCarInfoById(String car_number) {
        return usersmapper.QueryCarInfoById(car_number);
    }

    @Override
    public ArrayList<t_car_zu> QueryCarOrder(String username) {
        ArrayList<t_car_zu> t_car_zus = usersmapper.QueryCarOrder(username);
        if (t_car_zus != null){
            return t_car_zus;
        }
        return null;
    }

    @Override
    public Boolean deleteUser(String username) {
        Boolean aBoolean = usersmapper.deleteUser(username);
        sqlSession.commit();
        return aBoolean;
    }

    @Override
    public t_user QueryUserInfo(String username) {
        return usersmapper.QueryUserInfo(username);
    }

    @Override
    public Boolean changePassword(String username, String password) {
        Boolean aBoolean = usersmapper.changePassword(username, password);
        sqlSession.commit();
        return aBoolean;
    }

    @Override
    public ArrayList<t_car> QueryCar(String order) {
        return usersmapper.QueryCar(order);
    }

    @Override
    public ArrayList<t_car> QueryAllBrandAndCategory(String brand, String category) {
        return usersmapper.QueryAllBrandAndCategory(brand,category);
    }
}
